//package com.lxw.framework.untils;
//
//import com.mongodb.client.gridfs.GridFSBucket;
//import com.mongodb.client.gridfs.GridFSDownloadStream;
//import com.mongodb.client.gridfs.model.GridFSFile;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.mongodb.core.query.Criteria;
//import org.springframework.data.mongodb.gridfs.GridFsResource;
//import org.springframework.data.mongodb.gridfs.GridFsTemplate;
//import org.springframework.data.mongodb.core.query.Query;
//
//import java.io.IOException;
//import java.io.InputStream;
//
///**
// * 项目中，关于公共的与文件处理相关的工具类
// */
//@Slf4j
//public class FileUtils {
//    @Autowired
//    GridFsTemplate gridFsTemplate;
//    @Autowired
//    GridFSBucket gridFSBucket;
//    public InputStream getFileByIdMongDb(String id){
//        try{
//            GridFSFile gridFSFile = gridFsTemplate.findOne(Query.query(Criteria.where("_id").is(id)));
//            GridFSDownloadStream gridFSDownloadStream = gridFSBucket.openDownloadStream(gridFSFile.getObjectId());
//            GridFsResource gridFsResource = new GridFsResource(gridFSFile,gridFSDownloadStream);
//            return gridFsResource.getInputStream();
//        }catch (IOException e){
//            log.error("CmsPagePostService  getHtmlFileById"+e.getMessage());
//            e.printStackTrace();
//        }
//        return null;
//    }
//}
